#region Using Directives
using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
using System.Runtime.Serialization;
using System.Diagnostics.CodeAnalysis; 
#endregion Using Directives

namespace Minimal.Web
{
    /// <summary>
    /// An exception thrown by QueryString if a sub class of QueryString
    /// registers a QueryStringParameterAttribute with a key that
    /// is reserved by QueryString.
    /// </summary>
    [Serializable]
    [SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors")]
    public class ReservedKeyException
        : ArgumentException
    {
        #region Constructors
        /// <summary>
        /// Creates a new instance.
        /// </summary>
        /// <param name="key">The name of the reserved key.</param>
        public ReservedKeyException(string key)
            : base(ReservedKeyException.CreateMessage(key), key)
        {
            
        }

        /// <summary>
        /// Creates a new instance.
        /// </summary>
        /// <param name="message">A message for the exception.</param>
        /// <param name="key">The name of the reserved key.</param>
        public ReservedKeyException(string message, string key)
            : base(message, key)
        {
            
        }

        /// <summary>
        /// Constructory used for deserialization.
        /// </summary>
        /// <param name="info">SerializationInfo to use for deserialization.</param>
        /// <param name="context">The StreamingContext to use.</param>
        protected ReservedKeyException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        { }
        #endregion Constructors

        #region Properties
        
        #endregion Properties

        #region Methods
        #region CreateMessage
        private static string CreateMessage(string key)
        {
            if (!string.IsNullOrEmpty(key))
            {
                return string.Format(CultureInfo.InvariantCulture,
                    QueryStringResources.ReservedKeyExceptionMessage,
                    key);
            }
            else
            {
                return QueryStringResources.ReservedKeyExceptionMessageNoKey;
            }
        }
        #endregion CreateMessage
        #endregion Methods
    }
}
